<% layout('/layouts/default.html', {title: '药材收获信息管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-body">
			<#form:form id="searchForm" action="${ctx}/own/ownMedicineReceiptInformation/listDataNormal" method="post" class="form-inline "
			data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
			<#form:hidden name="status" value="${isNotBlank(receiptInformation.status) ? receiptInformation.status : '0'}"/>
			<#form:hidden name="isAll" value="${parameter.isAll}"/>
			<div class="form-group">
				<label class="control-label">${text('药材批次号')}：</label>
				<div class="control-inline">
					<#form:input path="medicineBatchId" maxlength="25" class="form-control width-120"/>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label">${text('药材名称')}：</label>
				<div class="control-inline">
					<#form:input path="varietyName" maxlength="50" class="form-control width-120"/>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label">${text('药材重量(g)')}：</label>
				<div class="control-inline">
					<#form:input path="weight" class="form-control width-120"/>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label">${text('所属区域代码')}：</label>
				<div class="control-inline">
					<#form:input path="areaCode" maxlength="6" class="form-control width-120"/>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label">${text('种植批次号')}：</label>
				<div class="control-inline">
					<#form:input path="batchId" maxlength="25" class="form-control width-120"/>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label">${text('收获时间')}：</label>
				<div class="control-inline">
					<#form:input path="harvestTime" readonly="true" maxlength="20" class="form-control Wdate-datetime"
					dataFormat="datetime" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',isShowClear:false});"/>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label">${text('种子来源')}：</label>
				<div class="control-inline">
					<#form:radio path="seedSource" dictType="own_medicine_seed_source" blankOption="true" class="form-control"/>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label">${text('施肥情况')}：</label>
				<div class="control-inline">
					<#form:radio path="fertilizer" dictType="own_medicine_fertilizer" blankOption="true" class="form-control"/>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label">${text('喷药情况')}：</label>
				<div class="control-inline">
					<#form:radio path="pesticide" dictType="own_medicine_pesticide" blankOption="true" class="form-control"/>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label">${text('药材批次码')}：</label>
				<div class="control-inline">
					<#form:input path="bmBatchCode" maxlength="50" class="form-control width-120"/>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label">${text('更新时间')}：</label>
				<div class="control-inline">
					<#form:input path="updateDate" class="form-control width-120"/>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label">${text('备注')}：</label>
				<div class="control-inline">
					<#form:input path="remarks" maxlength="255" class="form-control width-120"/>
				</div>
			</div>
			<div class="form-group">
				<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
				<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
			</div>
		</#form:form>
		<div class="row">
			<div class="col-xs-10 pr10">
				<table id="dataGrid"></table>
				<div id="dataGridPage"></div>
			</div>
			<div class="col-xs-2 pl0">
				<div id="selectData" class="tags-input"></div>
			</div>
		</div>
	</div>
</div>
</div>
<% } %>
<script>
	var selectData = ${isNotBlank(selectData!) ? selectData! : "{\}"},
	selectNum = 0, dataGrid = $('#dataGrid').dataGrid({
		searchForm: $("#searchForm"),
		columnModel: [
			{header:'${text("药材批次号")}', name:'medicineBatchId', index:'a.medicine_batch_id', width:150, align:"center"},
			{header:'${text("药材名称")}', name:'varietyName', index:'a.variety_name', width:150, align:"left"},
			{header:'${text("药材重量(g)")}', name:'weight', index:'a.weight', width:150, align:"right", formatter: function(val, obj, row, act){
					return js.formatNumber(val, 2, false, ''); // 数值类型格式化 (原始数值, 小数位数, 是否千分位, 默认值，金额情况下设置0.00);
				}},
			{header:'${text("所属区域代码")}', name:'areaCode', index:'a.area_code', width:150, align:"left"},
			{header:'${text("种植批次号")}', name:'batchId', index:'a.batch_id', width:150, align:"left"},
			{header:'${text("收获时间")}', name:'harvestTime', index:'a.harvest_time', width:150, align:"center"},
			{header:'${text("种子来源")}', name:'seedSource', index:'a.seed_source', width:150, align:"center", formatter: function(val, obj, row, act){
					return js.getDictLabel(${@DictUtils.getDictListJson('own_medicine_seed_source')}, val, '${text("未知")}', true);
				}},
			{header:'${text("施肥情况")}', name:'fertilizer', index:'a.fertilizer', width:150, align:"center", formatter: function(val, obj, row, act){
					return js.getDictLabel(${@DictUtils.getDictListJson('own_medicine_fertilizer')}, val, '${text("未知")}', true);
				}},
			{header:'${text("喷药情况")}', name:'pesticide', index:'a.pesticide', width:150, align:"center", formatter: function(val, obj, row, act){
					return js.getDictLabel(${@DictUtils.getDictListJson('own_medicine_pesticide')}, val, '${text("未知")}', true);
				}},
			{header:'${text("药材批次码")}', name:'bmBatchCode', index:'a.bm_batch_code', width:150, align:"left"},
			{header:'${text("更新时间")}', name:'updateDate', index:'a.update_date', width:150, align:"center"},
			{header:'${text("备注")}', name:'remarks', index:'a.remarks', width:150, align:"left"},
			{header:'行数据', name:'rowData', hidden:true, formatter: function(val, obj, row, act){
					return JSON.stringify(row);
				}}
		],
		autoGridHeight: function(){
			var height = $(window).height() - $('#searchForm').height() - $('#dataGridPage').height() - 75;
			$('.tags-input').height($('.ui-jqgrid').height() - 10);
			return height;
		},
		showCheckbox: '${parameter.checkbox}' == 'true',
		multiboxonly: false, // 单击复选框时再多选
		ajaxSuccess: function(data){
			$.each(selectData, function(key, value){
				dataGrid.dataGrid('setSelectRow', key);
			});
			initSelectTag();
		},
		onSelectRow: function(id, isSelect, event){
			if ('${parameter.checkbox}' == 'true'){
				if(isSelect){
					selectData[id] = JSON.parse(dataGrid.dataGrid('getRowData', id).rowData);
				}else{
					delete selectData[id];
				}
			}else{
				selectData = {};
				selectData[id] = JSON.parse(dataGrid.dataGrid('getRowData', id).rowData);
			}
			initSelectTag();
		},
		onSelectAll: function(ids, isSelect){
			if ('${parameter.checkbox}' == 'true'){
				for (var i=0; i<ids.length; i++){
					if(isSelect){
						selectData[ids[i]] = JSON.parse(dataGrid.dataGrid('getRowData', ids[i]).rowData);
					}else{
						delete selectData[ids[i]];
					}
				}
			}
			initSelectTag();
		},
		ondblClickRow: function(id, rownum, colnum, event){
			if ('${parameter.checkbox}' != 'true'){
				js.layer.$('#' + window.name).closest('.layui-layer')
						.find(".layui-layer-btn0").trigger("click");
			}
			initSelectTag();
		}
	});
	function initSelectTag(){
		selectNum = 0;
		var html = [];
		$.each(selectData, function(key, value){
			selectNum ++;
			html.push('<span class="tag" id="'+key+'_tags-input"><span>'+value.medicineBatchId+' </span>'
					+ '<a href="#" onclick="removeSelectTag(\''+key+'\');" title="取消选择">x</a></span>');
		});
		html.unshift('<div class="title">当前已选择<span id="selectNum">'+selectNum+'</span>项：</div>');
		$('#selectData').empty().append(html.join(''));
	}
	function removeSelectTag(key){
		delete selectData[key];
		dataGrid.dataGrid('resetSelection', key);
		$('#selectNum').html(--selectNum);
		$('#'+key+'_tags-input').remove();
	}
	function getSelectData(){
		return selectData;
	}
</script>
